home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 13.5 KB | 439 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPoint.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodutil
- #endif
-
- //========================================================================================
- // struct FW_CPoint
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(FW_PlatformPoint plfmPoint) :
- #ifdef FW_BUILD_WIN
- x (FW_IntToFixed(plfmPoint.x)),
- y (FW_IntToFixed(plfmPoint.y))
- #endif
- #ifdef FW_BUILD_MAC
- x (FW_IntToFixed(plfmPoint.h)),
- y (FW_IntToFixed(plfmPoint.v))
- #endif
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(const FW_CPoint &point) :
- x(point.x),
- y(point.y)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(const ODPoint &odPoint) :
- x (FW_ODFixedToFixed(odPoint.x)),
- y (FW_ODFixedToFixed(odPoint.y))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::FW_CPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint::FW_CPoint(const FW_CReadableStream& stream)
- {
- stream.Read(this, sizeof(FW_CPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(const FW_CPoint &point)
- {
- x = point.x;
- y = point.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(const ODPoint &odPoint)
- {
- x = FW_ODFixedToFixed(odPoint.x);
- y = FW_ODFixedToFixed(odPoint.y);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator=(FW_PlatformPoint plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = FW_IntToFixed(plfmPoint.x);
- y = FW_IntToFixed(plfmPoint.y);
- #endif
- #ifdef FW_BUILD_MAC
- x = FW_IntToFixed(plfmPoint.h);
- y = FW_IntToFixed(plfmPoint.v);
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Offset
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::Offset(FW_CFixed xx, FW_CFixed yy)
- {
- x += xx;
- y += yy;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator+=(const FW_CPoint &point)
- {
- x += point.x;
- y += point.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator-=(const FW_CPoint &point)
- {
- x -= point.x;
- y -= point.y;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator+=(const ODPoint &odPoint)
- {
- x += FW_ODFixedToFixed(odPoint.x);
- y += FW_ODFixedToFixed(odPoint.y);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator-=(const ODPoint &odPoint)
- {
- x -= FW_ODFixedToFixed(odPoint.x);
- y -= FW_ODFixedToFixed(odPoint.y);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator+(const FW_CPoint &point) const
- {
- FW_CPoint aPoint(x + point.x, y + point.y);
- return aPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-(const FW_CPoint &point) const
- {
- FW_CPoint aPoint(x - point.x, y - point.y);
- return aPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator+(const ODPoint &odPoint) const
- {
- return FW_CPoint(x + FW_ODFixedToFixed(odPoint.x), y + FW_ODFixedToFixed(odPoint.y));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-(const ODPoint &odPoint) const
- {
- return FW_CPoint(x - FW_ODFixedToFixed(odPoint.x), y - FW_ODFixedToFixed(odPoint.y));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-() const
- {
- return FW_CPoint(-x, -y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator+=(FW_SPlatformPoint plfmPoint)
- {
- x += FW_IntToFixed(plfmPoint.X());
- y += FW_IntToFixed(plfmPoint.Y());
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-=
- //----------------------------------------------------------------------------------------
-
- FW_CPoint& FW_CPoint::operator-=(FW_SPlatformPoint plfmPoint)
- {
- x -= FW_IntToFixed(plfmPoint.X());
- y -= FW_IntToFixed(plfmPoint.Y());
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator+
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator+(FW_SPlatformPoint plfmPoint) const
- {
- return FW_CPoint(x + FW_IntToFixed(plfmPoint.X()), y + FW_IntToFixed(plfmPoint.Y()));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator-
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::operator-(FW_SPlatformPoint plfmPoint) const
- {
- return FW_CPoint(x - FW_IntToFixed(plfmPoint.X()), y - FW_IntToFixed(plfmPoint.Y()));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::AsPlatformPoint
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::AsPlatformPoint(FW_PlatformPoint& plfmPoint) const
- {
- #ifdef FW_BUILD_MAC
- plfmPoint.h = x.AsInt();
- plfmPoint.v = y.AsInt();
- #endif
- #ifdef FW_BUILD_WIN
- plfmPoint.x = x.AsInt();
- plfmPoint.y = y.AsInt();
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPoint::operator==(const FW_CPoint& pt) const
- {
- return x == pt.x && y == pt.y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator!=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPoint::operator!=(const FW_CPoint& pt) const
- {
- return x != pt.x || y != pt.y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPoint::operator==(const ODPoint& odPoint) const
- {
- return x.AsODFixed() == odPoint.x && y.AsODFixed() == odPoint.y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator!=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPoint::operator!=(const ODPoint& odPoint) const
- {
- return x.AsODFixed() != odPoint.x || y.AsODFixed() != odPoint.y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator[]
- //----------------------------------------------------------------------------------------
-
- FW_CFixed& FW_CPoint::operator[](FW_XYSelector selector)
- {
- return * (FW_CFixed *) (selector == FW_kVertical ? &y : &x);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::operator[]
- //----------------------------------------------------------------------------------------
-
- FW_CFixed FW_CPoint::operator[](FW_XYSelector selector) const
- {
- return * (FW_CFixed *) (selector == FW_kVertical ? &y : &x);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Map
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::Map(const FW_CRect& srcRect, const FW_CRect& destRect)
- {
- FW_CFixed xDelta = x - srcRect.left;
- FW_CFixed yDelta = y - srcRect.top;
-
- FW_CFixed yRatio = FW_IntToFixed(1);
-
- if (srcRect.Width())
- {
- FW_CFixed xRatio = destRect.Width() / srcRect.Width();
- xDelta *= xRatio;
- }
-
- if (srcRect.Height())
- {
- FW_CFixed yRatio = destRect.Height() / srcRect.Height();
- yDelta *= yRatio;
- }
-
- x = destRect.left + xDelta;
- y = destRect.top + yDelta;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::Transform(Environment* ev, ODTransform* transform)
- {
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) this) =
- #endif
- transform->TransformPoint(ev, (ODPoint*) this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CPoint::InverseTransform(Environment* ev, ODTransform* transform)
- {
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) this) =
- #endif
- transform->InvertPoint(ev, (ODPoint*) this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::TransformCopy
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::TransformCopy(Environment* ev, ODTransform* transform) const
- {
- FW_CPoint point(*this);
-
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) & point) =
- #endif
- transform->TransformPoint(ev, (ODPoint*)&point);
-
- return point;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::InverseTransformCopy
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPoint::InverseTransformCopy(Environment* ev, ODTransform* transform) const
- {
- FW_CPoint point(*this);
-
- #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
- * ((ODPoint *) & point) =
- #endif
- transform->InvertPoint(ev, (ODPoint*)&point);
-
- return point;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CPoint& point)
- {
- stream.Write(&point, sizeof(FW_CPoint));
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator>>
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CPoint& point)
- {
- stream.Read(&point, sizeof(FW_CPoint));
- return stream;
- }
-